#ifndef _CRT_ATOMIC_H_
#define _CRT_ATOMIC_H_

#include <crt_define.h>

#ifdef __cplusplus
extern "C"
{
#endif

#if (TARGET_OS == OS_POSIX)
    typedef long atomic_type;
#elif (TARGET_OS == OS_WINDOWS)
    typedef long atomic_type;
#elif (TARGET_OS == OS_DARWIN)
    typedef int32_t atomic_type;
#endif


typedef struct _atomic_s _atomic_t;

struct _atomic_s {
    atomic_type value;
};


atomic_type	xadd(atomic_type* ptr);
atomic_type	xdel(atomic_type* ptr);

atomic_type	_atomic_init(_atomic_t *self);
atomic_type	_atomic_uninit(_atomic_t *self);
atomic_type	_atomic_add(_atomic_t *self);
atomic_type	_atomic_del(_atomic_t *self);

void	    _atomic_set(_atomic_t *self, void *value);
atomic_type	_atomic_cas(_atomic_t *self, atomic_type oldval, atomic_type newval);
void	    _atomic_xchg(_atomic_t *self, void *value);


#ifdef __cplusplus
}
#endif

#endif


